package com.wtwd.device.service.impl;


import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wtwd.device.dao.GroupLanguageMapper;
import com.wtwd.device.model.entity.GroupLanguage;
import com.wtwd.device.service.GroupLanguageService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mjy
 * @since 2023-03-01
 */
@Service
public class GroupLanguageServiceImpl extends ServiceImpl<GroupLanguageMapper, GroupLanguage> implements GroupLanguageService {

    @Resource
    private GroupLanguageMapper groupLanguageMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean synchronizationLanguage(Integer groupId, List<GroupLanguage> groupLanguages) {
        deleteByGroupId(groupId);
        return saveBatch(groupLanguages);
    }

    @Override
    public boolean deleteByGroupId(Integer groupId) {
        return groupLanguageMapper.deleteByGroupId(groupId) > 0 ? true : false;
    }

    @Override
    public List<GroupLanguage> getLanguageByGroupIdsAndType(List<Integer> groupIds, String type) {
        return new LambdaQueryChainWrapper<>(groupLanguageMapper)
                .in(GroupLanguage::getGroupId, groupIds)
                .eq(GroupLanguage::getType, type)
                .list();
    }
}
